﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using TrilhaImovel.Core.Repositories;
using TrilhaImovel.Core.Entities;
using System.Globalization;

namespace TrilhaImovel.UI.Controllers
{
    [HandleError]
    public class EstateController : Controller
    {
        private readonly IEstateRepository estateRepository;

        public EstateController(IEstateRepository repository)
        {
            estateRepository = repository;
        }

        public ActionResult ViewDetail(int estateId)
        {
            var estate = estateRepository.Get(estateId);

            ViewData["Id"] = estate.Id;
            ViewData["EstateName"] = string.Empty;
            ViewData["OperationAndPropertyType"] = string.Format("{0} - {1}", 
                                                    ConvertEnums.DisplayOperationType(estate.OperationType),  
                                                    ConvertEnums.DisplayPropertyType(estate.PropertyType));

            ViewData["PriceOrRentValue"] = estate.PriceOrRentValue.ToString(new CultureInfo("pt-BR"));
            ViewData["Street1"] = estate.Address.Street;
            ViewData["Street2"] = string.Format("{0}, {1} - {2}", estate.Address.Neighborhood, estate.Address.City, estate.Address.State);
            ViewData["AreaInSquareMeter"] = estate.AreaInSquareMeter;
            ViewData["RealStateAgencyName"] = estate.RealStateAgency.Name;

            return View();
        }
    }
}
